package com.smag.web.controller.echarts.pie;

import com.smag.common.annotation.Log;
import com.smag.common.core.controller.BaseController;
import com.smag.common.core.domain.AjaxResult;
import com.smag.common.core.page.TableDataInfo;
import com.smag.common.enums.BusinessType;
import com.smag.common.utils.poi.ExcelUtil;
import com.smag.echarts.domain.EchartsPiePest;
import com.smag.echarts.service.EchartsPiePestService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController("piePestController")
@RequestMapping("/echarts/pie/pest")
public class PestController extends BaseController {
    @Resource
    private EchartsPiePestService echartsPiePestService;

    @GetMapping("/listAll")
    public AjaxResult getPestList() {

        return echartsPiePestService.getPestList();
    }

    /**
     * 查询病虫灾害列表
     */
    @PreAuthorize("@ss.hasPermi('system:pest:list')")
    @GetMapping("/list")
    public TableDataInfo list(EchartsPiePest echartsPiePest)
    {
        startPage();
        List<EchartsPiePest> list = echartsPiePestService.selectEchartsPiePestList(echartsPiePest);
        return getDataTable(list);
    }

    /**
     * 导出病虫灾害列表
     */
    @PreAuthorize("@ss.hasPermi('system:pest:export')")
    @Log(title = "病虫灾害", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EchartsPiePest echartsPiePest)
    {
        List<EchartsPiePest> list = echartsPiePestService.selectEchartsPiePestList(echartsPiePest);
        ExcelUtil<EchartsPiePest> util = new ExcelUtil<EchartsPiePest>(EchartsPiePest.class);
        util.exportExcel(response, list, "病虫灾害数据");
    }

    /**
     * 获取病虫灾害详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return echartsPiePestService.selectEchartsPiePestById(id);
    }

    /**
     * 新增病虫灾害
     */
    @PreAuthorize("@ss.hasPermi('system:pest:add')")
    @Log(title = "病虫灾害", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EchartsPiePest echartsPiePest)
    {
        return echartsPiePestService.insertEchartsPiePest(echartsPiePest);
    }

    /**
     * 修改病虫灾害
     */
    @PreAuthorize("@ss.hasPermi('system:pest:edit')")
    @Log(title = "病虫灾害", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EchartsPiePest echartsPiePest)
    {
        return echartsPiePestService.updateEchartsPiePest(echartsPiePest);
    }

    /**
     * 删除病虫灾害
     */
    @PreAuthorize("@ss.hasPermi('system:pest:remove')")
    @Log(title = "病虫灾害", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return echartsPiePestService.deleteEchartsPiePestByIds(ids);
    }
}
